package com.itlong.cloud.controller.operatingReport;

import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.noncore.property.IPropertyOperatingReportServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      物业访客管理Controller
 * </desc>
 *
 * @createDate 2018/06/27
 */
@RestController
@RequestMapping("/statistics")
public class PropertyOperatingReportStatisticsController {

    @Autowired
    IPropertyOperatingReportServiceClient iPropertyOperatingReportServiceClient;

    /**
     * <desc>
     *      获取物业运营统计报表数据
     * <desc/>
     *
     * @param projectId
     * @param startTime
     * @param endTime
     * @return  MessageVO 标准格式化响应结果
     * @author Jiaqi.X
     * @createDate 2018/08/13
     */
    @ResponseBody
    @AuthAccessRequired
    @PostMapping(path = "/report/chargeStatistics")
    public Object getVisitorPassRecordByPage(String projectId,String startTime,String endTime) throws Exception {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
            startTime = request.getAttribute("startTime") == null ? "" : request.getAttribute("startTime").toString();
            endTime = request.getAttribute("endTime") == null ? "" : request.getAttribute("endTime").toString();
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),
                    iPropertyOperatingReportServiceClient.chargeStatistics(projectId,startTime,endTime));
        } catch (Exception e) {
            throw new DataAccessException("【物业_运营报表_收费统计】获取物业运营统计报表数据失败", e);
        }
    }



}